import 'package:fluttertoast/fluttertoast.dart';
import 'package:gsy_flutter_app/common/style/GSYStyle.dart';

/// 作者: Tao
/// 日期: 2024/1/17
/// 时间: 14:55
/// 描述: 请求返回码
class Code {
  //网络错误
  static const NETWORK_ERROR = 1;

//网络超时
  static const NETWORK_TIMEOUT = 2;

//网络返回数据格式化一次
  static const NETWORK_JSON_EXCEPTION = 3;

  static const SUCCESS = 200;

  /// 方法描述: 根据错误码toast显示错误消息，并返回错误信息
  /// [code] 错误码
  /// [message] 错误内容
  /// return: [String]
  static errorHandleFunction(code, message) {
    switch(code) {
      case 401:
        Fluttertoast.showToast(msg: GSYStrings.network_error_401);
        return GSYStrings.network_error_401;
      case 403:
        Fluttertoast.showToast(msg: GSYStrings.network_error_403);
        return GSYStrings.network_error_403;
      case 404:
        Fluttertoast.showToast(msg: GSYStrings.network_error_404);
        return GSYStrings.network_error_404;
      case NETWORK_TIMEOUT:
      //超时
        Fluttertoast.showToast(msg: GSYStrings.network_error_timeout);
        return GSYStrings.network_error_timeout;
      default:
        Fluttertoast.showToast(msg: GSYStrings.network_error_unknown + " " + message);
        return GSYStrings.network_error_unknown;
    }
  }
}
